<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>报名点新增</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="css/layuiAdmin.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->

</head>
<body>

<div class="xyxx">
    <div class="layui-card-header">报名点新增</div>
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" action="" lay-filter="component-form-element">
            <h5 class="lheight">上级机构</h5>
            <div class="layui-row layui-col-space10">
                <div class="layui-inline layui-col-lg3 layui-col-sm6">
                    <label class="layui-form-label">总校：</label>
                    <div class="layui-input-block">
                        <select id="gatherSchoolId" name="gatherSchoolId">
                            <option value="0">选择</option>
                            <option value="2">翰阳驾校</option>
                            <option value="4">启富驾校</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-lg3 layui-col-sm6">
                    <label class="layui-form-label">分校：</label>
                    <div class="layui-input-block">
                        <select id="branchSchoolId" name="branchSchoolId">
                            <option value="0">选择</option>
                            <option value="22">翰阳驾校一分校</option>
                            <option value="23">翰阳驾校二分校</option>
                            <option value="27">启富驾校一分校</option>
                            <option value="28">启富驾校二分校</option>
                        </select>
                    </div>
                </div>


            </div>

            <div class="layui-row layui-col-space10">
                <div class="layui-inline  layui-col-sm6">
                    <label class="layui-form-label">报名点名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" id="name">
                        <input type="hidden" name="id" class="layui-input" id="id">
                    </div>
                </div>
                <div class="layui-col-sm6"><h6 class="pleft17">报名点名称，汉字+字母+数字，100字符内</h6></div>
            </div>


            <div class="layui-row layui-col-space10">
                <div class="layui-inline  layui-col-sm6">
                    <label class="layui-form-label">报名点地址：</label>
                    <div class="layui-input-block">
                        <input type="text" name="address" class="layui-input" id="address">
                    </div>
                </div>
                <div class="layui-col-sm6">
                    <label class="layui-form-label">经纬度：</label>
                    <div class="layui-input-block" style="position: relative;">
                        <input type="text" id="lonandlat" name="lonandlat" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style=" margin-right: 10px; float: left;">
                        <input id="Button1" type="button" class="layui-btn add_btn" value="搜索"  style="position: absolute; right: 0;"  />
                    </div>
                </div>
            </div>
            <div class="layui-row layui-col-space10">
                <div class="layui-inline  layui-col-sm6">
                    <label class="layui-form-label">联系人电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" class="layui-input" id="mobile">
                    </div>
                </div>
                <div class="layui-col-sm6">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-block" style="position: relative;">
                        <input type="text" name="contacts" id="contacts" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style=" margin-right: 10px; float: left;">
                    </div>
                </div>
            </div>

            <!--模板-->


            <div class="layui-form-item layui-col-space10">
                <div class="layui-input-block">
                    <button type="reset" class="layui-btn layui-btn-primary btn-left">关闭</button>
                    <button class="layui-btn btn-left add_btn" lay-submit lay-filter="component-form-element">提交</button>

                </div>
            </div>
        </form>
    </div>
</div>


</body>

<script>

    var table;
    $(function () {
        var postData={"id":getQueryString("id")}
        $.ajax({
            type: 'POST',
            url: 'http://localhost:60061/api/register/info',
            contentType: "application/x-www-form-urlencoded",
            data: postData,
            success: function (r) {
                var data=r.data;
                /*form.val("component-form-element", {
                    "branchSchoolId": date.parentId
                    ,"name": data.name
                    ,"address": 3
                    ,"lonandlat": data.longitude+","+data.latitude
                    ,"mobile": data.mobile
                    ,"contacts": mobile.contacts
                })*/
                console.log(data);
                $("#branchSchoolId").val(data.branchSchoolId);
                $("#name").val(data.name);
                $("#gatherSchoolId").val(data.gatherSchoolId);
                $("#address").val(data.address);
                $("#lonandlat").val(data.longitude+","+data.latitude);
                $("#mobile").val(data.mobile);
                $("#contacts").val(data.contacts);
                $("#id").val(data.id);

            },

        });
    });

    layui.use(['table','form','laydate','layer','upload'], function() {
        table = layui.table;
        var form = layui.form,
            laydate = layui.laydate,
            layer=layui.layer,
            $ = layui.jquery,
            upload = layui.upload;

        //常规用法
        laydate.render({
            elem: '#activeTime'
            ,range: true
        });

        //监听提交
        form.on('submit(component-form-element)', function(data){
            var tude=data.field.lonandlat.split(",");
            data.field.longitude=tude[0];
            data.field.latitude=tude[1];
            if(data.field.branchSchoolId==null||data.field.branchSchoolId==""){
                data.field.parentId=data.field.gatherSchoolId
            }else{
                data.field.parentId=data.field.branchSchoolId
            }
            console.log(JSON.stringify(data.field));
            $.ajax({
                type: 'POST',
                url: 'http://localhost:60061/api/register/update',
                contentType: "application/x-www-form-urlencoded",
                data: data.field,
                success: function (r) {
                    layer.alert(r.message);
                    reset();
                },
            });
            return false;
        });

    });


</script>
</html>